package com.shrio.word;

import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
import org.apache.poi.xwpf.usermodel.XWPFRun;

import java.io.FileOutputStream;
import java.io.IOException;

public class WordGenerator {

    public static void generateWord(String outputPath) throws IOException {
        XWPFDocument document = new XWPFDocument();

        // 创建段落
        XWPFParagraph paragraph = document.createParagraph();
        XWPFRun run = paragraph.createRun();
        run.setText("Hello, World!");

        // 保存文档
        FileOutputStream out = new FileOutputStream(outputPath);
        document.write(out);
        out.close();

        System.out.println("Word document generated successfully!");
    }

    public static void main(String[] args) {
        String outputPath = "E:/word/降水Merge.docx";

        try {
            generateWord(outputPath);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}